#define _CRT_SECURE_NO_WARNINGS 1
#include"Stack.h"

void test1()
{
	Stack p;
	StackInit(&p);
	StackPush(&p, 1);
	StackPush(&p, 2);
	StackPush(&p, 3);
	StackPush(&p, 4);
	StackPush(&p, 5);
	while (!StackEmpty(&p))
	{
		printf("%d ", StackTop(&p));
		StackPop(&p);
	}
	printf("\n");
	StackDestroy(&p);
	

}
bool isValid(char* s) {
    Stack st;
    StackInit(&st);
    char top;
    while (*s)
    {
        if (*s == '(' || *s == '{' || *s == '[')
        {
            StackPush(&st, *s);
        }
        else
        {
            if (StackEmpty(&st))
            {
                StackDestroy(&st);
                return false;
            }
            top = StackTop(&st);
            StackPop(&st);
            if ((*s == ')' && top != '(') ||
                (*s == ']' && top != '[')
                || (*s == '}' && top != '{'))
            {
                return false;
            }
        }
        s++;
    }
    bool ret = StackEmpty(&st);
    return ret;

}

int main()
{
    char arr[4] = "{[}]";
    isValid(&arr);
	//test1();
	return 0;
}